<extend name="admin/main"/>

<block name="title">
    <title>留言信息</title>
</block>

<block name="css"></block>

<block name="heading">留言信息</block>

<block name="content">
    <div class="panel panel-success">
        <div class="panel-heading">Leave Words</div>
        <div class="panel-body">
            <form class="form" method="get">
                <div class="form-group">
                    <label for="search"></label>
                    <div class="col-md-4">
                        <input type="text" id="search" name="search" value="{$search}" class="form-control">
                    </div>
                    <button class="btn btn-success-alt">搜索</button>
                </div>
            </form>
            <table class="table table-bordered table-hover text-center">
                <thead>
                <tr class="text-uppercase">
                    <th class="text-center">#</th>
                    <th class="text-center">name</th>
                    <th class="text-center">qq</th>
                    <th class="text-center">tel</th>
                    <th class="text-center">email</th>
                    <th class="text-center">comment</th>
                    <th class="text-center">updated_at</th>
                    <th class="text-center">created_at</th>
                    <th class="text-center">Action</th>
                </tr>
                </thead>
                <tbody>
                <foreach name="data" item="item">
                    <tr data-id="{$item.id}">
                        <td>{$item.id}</td>
                        <td>{$item.name}</td>
                        <td>{$item.qq}</td>
                        <td>{$item.tel}</td>
                        <td>{$item.email}</td>
                        <td>{$item.comment}</td>
                        <td>{$item.updated_at}</td>
                        <td>{$item.created_at}</td>
                        <td>
                            <button class="btn btn-sm btn-warning-alt lm-d"><i class="fa fa-trash"></i></button>
                        </td>
                    </tr>
                </foreach>
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="12">
                        {$leaveWords->link(['$search' => $search])}
                    </td>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>
</block>

<block name="js">
    <script type="text/javascript" src="__PUBLIC__/assets/demo/demo.js"></script>
    <script type="text/javascript" src="__PUBLIC__/assets/demo/demo-switcher.js"></script>
    <script type="text/javascript" src="__PUBLIC__/assets/plugins/bootbox/bootbox.js"></script>
    <script>
        $(document).ready(function () {
            $('.lm-d').click(function () {
                var id = $(this).parents('tr').attr('data-id');
                bootbox.confirm('是否删除?', function (res) {
                    if(res === true) {
                        $.post('/admin/setting/lm/delete', {id: id}, function (res) {
                            var data =JSON.parse(res);
                            if (data.success === false) {
                                new PNotify({
                                    title: 'Oh On!',
                                    text: JSON.stringify(data.data),
                                    type: 'error',
                                    icon: 'ti ti-info-alt',
                                    styling: 'fontawesome'
                                });
                            } else {
                                window.location.reload();
                            }
                        });
                    }
                })
            })
        });
    </script>
</block>
